<template>
  <div>
    <base-list ref="jobVehicle"
               :condition="condition"
               :datas.sync="jobVehicle"
               :pageSearch="pageSearch">
      <el-form :inline="true"
               :model="condition"
               class="search-form"
               slot="search"
               label-width="80px">
        <el-row>
          <el-col :span="7" class="search-width4">
            <el-form-item label="车　　号">
              <auto-search-vehicle-no @select="v=>condition['search_LIKE_resourceNo']=v"></auto-search-vehicle-no>
            </el-form-item>
          </el-col>
          <el-col :span="7" class="search-width4">
            <el-form-item label="车辆类型">
              <auto-search-dic @selectName="v=>condition['search_LIKE_typeName']=v"
                               :name="condition['search_LIKE_typeName']"
                               code="JOB_CLLX"></auto-search-dic>
            </el-form-item>
          </el-col>
          <el-col :span="7" class="search-width4">
            <el-form-item label="车辆类别">
              <auto-search-dic @selectName="v=>condition['search_LIKE_categoryName']=v"
                               :name="condition['search_LIKE_categoryName']"
                               code="JOB_CLLB"></auto-search-dic>
            </el-form-item>
          </el-col>
        <!-- </el-row> -->
        <!-- <el-row> -->
          <el-col :span="5" class="search-width4">
            <el-form-item label="是否可用">
              <el-select v-model="condition['search_EQ_valid']"
                         placeholder="请选择"
                         clearable>
                <el-option v-for="[key, val] in _dictTrueOrFalse"
                           :key="key"
                           :label="val"
                           :value="key"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="3">
            <el-button type="primary"
                       icon="el-icon-search"
                       @click="loadData"
                       class="ml-80">查 询</el-button>
          </el-col>
        </el-row>
      </el-form>
      <el-row slot="status">
        <el-col :span="24">
          <el-button type="primary" formVisible="true"
                       icon="el-icon-plus"
                       @click="handleDialogFormOpen(false)"
                       v-if="power('WJOB_BASEMGR_VEHICLE:ADD')">
              新增
            </el-button>
        </el-col>
      </el-row>
      <el-table slot="list"
                :data="jobVehicle"
                border
                stripe
                max-height="500">
         <el-table-column type="index"
                         fixed="left"
                         label="序号"
                         width="55">
          <template slot-scope="scope">
            {{ scope.$index+1 }}
          </template>
        </el-table-column>
        <el-table-column prop="resourceNo"
                         label="车号"
                         
                         min-width="130"></el-table-column>
        <el-table-column prop="plateNumber"
                         label="车牌号"
                         
                         min-width="130"></el-table-column>
        <el-table-column prop="typeName"
                         label="车辆类型"
                         
                         min-width="130"></el-table-column>
        <el-table-column prop="categoryName"
                         label="车辆类别"
                         
                         min-width="120"></el-table-column>
        <el-table-column prop="teu"
                         label="载重量/可拖标箱数"
                         
                         min-width="150"></el-table-column>
        <el-table-column prop="weight"
                         label="车重"
                         
                         min-width="120"></el-table-column>
        <el-table-column prop="orgName"
                         label="所属单位"
                         
                         min-width="200"></el-table-column>
        <el-table-column prop="valid"
                         label="是否可用"
                         
                         min-width="120">
          <template slot-scope="scope">
            {{ scope.row.valid | _filterTrueOrFalse }}
          </template>
        </el-table-column>
        <el-table-column prop="resourceDescribe"
                         label="备注"
                         
                         min-width="200"></el-table-column>
        <el-table-column fixed="right"
                         align="center"
                         label="操作"
                         
                         width="140">
          <template slot-scope="scope">
            <el-button size="small"
                       type="text"
                       @click="handleDialogFormOpen(true,scope.row)">
              编辑
            </el-button>
            <el-button type="text"
                       class="danger"
                       size="small"
                       @click="handleRemove(scope.row)">删除
            </el-button>
          </template>
        </el-table-column>
      </el-table>
    </base-list>
    <job-vehicle-form ref="jobVehicleForm"
                      @load="loadData"></job-vehicle-form>
  </div>
</template>

<script>
import {
  deleteJobVehicle,
  getJobVehicleList
} from '@/api/baseResource/baseResource'
import autoSearchOrg from '@/components/autocomplete/autoSearchOrg'
import autoSearchDic from '@/components/autocomplete/autoSearchDic'
import autoSearchVehicleNo from '@/components/autocomplete/autoSearchVehicleNo'
import jobVehicleForm from './jobVehicleForm'

export default {
  name: 'carManage',
  components: {
    jobVehicleForm,
    autoSearchOrg,
    autoSearchVehicleNo,
    autoSearchDic
  },
  data() {
    return {
      condition: {}, // 查询条件
      jobVehicle: [], // table数组
      pageSearch: getJobVehicleList, // 分页查询api接口
      id: ''
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.loadData()
    })
  },
  methods: {
    loadData() {
      this.$refs.jobVehicle.loadData()
    },
    handleDialogFormOpen(bool, item) {
      if (bool) {
        this.$refs.jobVehicleForm.form = JSON.parse(JSON.stringify(item))
        this.$refs.jobVehicleForm.isEdit = true
        this.$refs.jobVehicleForm.dialogForm = true
      } else {
        this.$refs.jobVehicleForm.dialogForm = true
      }
    },
    handleRemove(item) {
      this.$confirm(`是否删除该数据?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deleteJobVehicle(item.id).then(res => {
            this.$message({
              type: 'success',
              message: `删除成功!`
            })
            this.loadData()
          })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消'
          })
        })
    }
  }
}
</script>

<style scoped>
</style>
